package fei.yuzhi.com.loveflowers.fragment.firstpagefragment.autoscroll;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import fei.yuzhi.com.loveflowers.R;
import fei.yuzhi.com.loveflowers.bean.firstpageautobean.ItemBean;

/**
 * Created by My on 2016/10/13.
 */
public class AutoScrollGridAdapter extends BaseAdapter {
    private Context context;
    private List<ItemBean> itemBeanList;
    public AutoScrollGridAdapter(Context context,List<ItemBean> itemBeanList){
        this.context=context;
        this.itemBeanList=itemBeanList;
    }
    @Override
    public int getCount() {
        return itemBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return itemBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_firstpage_autoscrool_gird,null);
            holder=new ViewHolder();
            holder.goods_image= (ImageView) convertView.findViewById(R.id.item_first_auto_iv);
            holder.goods_name= (TextView) convertView.findViewById(R.id.item_first_auto_name);
            holder.goods_promotion_price= (TextView) convertView.findViewById(R.id.item_first_auto_price);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(itemBeanList.get(position).getGoods_image()).into(holder.goods_image);
        holder.goods_name.setText(itemBeanList.get(position).getGoods_name());
        holder.goods_promotion_price.setText("￥"+itemBeanList.get(position).getGoods_promotion_price());
        return convertView;
    }
    static class ViewHolder{
        ImageView goods_image;
        TextView goods_name,goods_promotion_price;
    }
}
